<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<table mat-table [dataSource]="notifications" class="notifications" id="notifications" aria-label="Notifications list">
  <ng-container matColumnDef="name">
    <th mat-header-cell *matHeaderCellDef id="name">Name</th>
    <td mat-cell *matCellDef="let element">
      {{ element.name }}
    </td>
  </ng-container>

  <ng-container matColumnDef="subscribedEvents">
    <th mat-header-cell *matHeaderCellDef id="subscribedEvents">Events subscribed</th>
    <td mat-cell *matCellDef="let element">
      <span class="gio-badge-neutral">{{ element.subscribedEvents }} events</span>
    </td>
  </ng-container>

  <ng-container matColumnDef="notifier">
    <th mat-header-cell *matHeaderCellDef id="notifier">Notifier</th>
    <td mat-cell *matCellDef="let element">
      <span class="gio-badge-neutral" *ngIf="element.notifier">{{ element.notifier.name }}</span>
    </td>
  </ng-container>

  <ng-container matColumnDef="actions">
    <th mat-header-cell *matHeaderCellDef id="actions">Action</th>
    <td mat-cell *matCellDef="let element">
      <div class="notifications__actions">
        <button
          *ngIf="canUpdate"
          mat-icon-button
          aria-label="Edit notification"
          matTooltip="Edit notification"
          (click)="edit.emit(element.id)"
          data-testid="edit-button"
        >
          <mat-icon svgIcon="gio:edit-pencil"></mat-icon>
        </button>

        <button
          *ngIf="canDelete && !element.isPortalNotification"
          mat-icon-button
          aria-label="Delete notification"
          matTooltip="Delete notification"
          data-testid="delete-button"
          (click)="delete.emit(element)"
        >
          <mat-icon svgIcon="gio:trash"></mat-icon>
        </button>
      </div>
    </td>
  </ng-container>

  <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
  <tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>

  <!-- Row shown when there is no data -->
  <tr class="mat-mdc-row mdc-data-table__row" *matNoDataRow>
    <td *ngIf="!loading" class="mat-mdc-cell mdc-data-table__cell" [attr.colspan]="displayedColumns.length">
      {{ 'No notifications to display.' }}
    </td>
    <td *ngIf="loading" class="mat-mdc-cell mdc-data-table__cell" [attr.colspan]="displayedColumns.length">
      <gio-loader></gio-loader>
    </td>
  </tr>
</table>
